package com.enki.cigarettes.repository;

import com.enki.cigarettes.entity.CouponT;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.Date;
import java.util.List;

/**
 * @author WCS.Wang
 * @version V1.0
 * @Package com.enki.cigarettes.repository
 * @Name e-cigarettes-shop-api-module
 * @Description: TODO 优惠券数据层
 * @date 2019-07-19
 */
public interface CouponTRepository  extends PagingAndSortingRepository<CouponT, String> {

    // 获取优惠券信息
    CouponT findOneByIdAndStoreIdAndStatus(String id, String storeId, boolean status);

    CouponT findOneById(String id);

    List<CouponT> findAll(Specification specification);

    Page<CouponT> findAll(Specification specification, Pageable pageable);

    // 根据优惠券状态、可使用时间
    List<CouponT> findByStatusAndEffectiveEndTimeGreaterThan(boolean status, Date effectiveEndTime, Sort sort);

    List<CouponT> findTop2ByStatusAndEffectiveEndTimeGreaterThan(boolean status, Date effectiveEndTime, Sort sort);
}

